<?php
/**
 * 车辆类型相关接口请求参数验证器
 * 发仔<i@fazi.me> 2018-07-09
 */

namespace app\open\validate;
class SettingValidate extends CommonValidate
{
    //验证
    protected $rule = [
        'key' =>  'require|alphaDash|checkUnique',
        'val' =>  'require',
    ];

    // 默认值
    protected $default = [
    ];

    protected $message = [
        'key.checkUnique' => '配置名已经存在',
    ];

    protected $scene = [
        'add' => [
            'key','val'
        ],
        'edit' => [
            'val'
        ],
        'delete' => ['key']
    ];

    protected function checkUnique($value) {
        $rslt = (new \app\open\model\Setting())->where('key',$value)->find();
        return $rslt ? false : true;
    }

}